home *** CD-ROM | disk | FTP | other *** search
- // RegenProps.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "RegenWizard.h"
- #include "RegenProps.h"
-
- #include "RegenWizardAW.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CRegenProps dialog
-
-
- CRegenProps::CRegenProps(CRegenWizardAppWiz *pMain, CWnd* pParent /*=NULL*/)
- : CAppWizStepDlg(CRegenProps::IDD),
- m_pclsMain(pMain)
- {
- //{{AFX_DATA_INIT(CRegenProps)
- m_strName = _T("");
- m_strValue = _T("");
- m_iPropType = 0;
- //}}AFX_DATA_INIT
-
- m_iPropCount = 0;
-
- m_pclsMain->m_Dictionary[_T("PropertiesCount")] = _T("0");
- m_pclsMain->m_Dictionary[_T("RegenPropertiesGenerated")] = _T("");
- m_pclsMain->m_Dictionary[_T("RegenPropertiesStringTable")] = _T("");
- m_pclsMain->m_Dictionary[_T("RegenPropertiesValuesStringTable")] = _T("");
- m_pclsMain->m_Dictionary[_T("RegenPropertiesIDS")] = _T("");
- }
-
-
- void CRegenProps::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRegenProps)
- DDX_Control(pDX, IDC_PROP_LIST, m_listAll);
- DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
- DDX_Text(pDX, IDC_EDIT_VALUE, m_strValue);
- DDX_CBIndex(pDX, IDC_COMBO_TYPE, m_iPropType);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CRegenProps, CAppWizStepDlg)
- //{{AFX_MSG_MAP(CRegenProps)
- ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
- ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
- ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CRegenProps message handlers
- const char* strTypes[14] =
- {
- "byte",
- "char",
- "unsigned short",
- "short",
- "unsigned long",
- "long",
- "unsigned int",
- "int",
- "float",
- "double",
- "BOOL",
- "BSTR",
- "SCODE",
- "Cyrrency"
- };
-
- const char* strVarSizes[14] =
- {
- "UI1",
- "I1",
- "UI2",
- "I2",
- "UI4",
- "I4",
- "UINT",
- "INT",
- "R4",
- "R8",
- "BOOL",
- "BSTR",
- "ERROR",
- "CY"
- };
-
- const char* strVarFields[14] =
- {
- ".bVal",
- ".cVal",
- ".uiVal",
- ".iVal",
- ".ulVal",
- ".lVal",
- ".uintVal",
- ".intVal",
- ".fltVal",
- ".dblVal",
- ".boolVal",
- ".bstrVal",
- ".scode",
- ".cyVal"
- };
-
- void CRegenProps::OnButtonAdd()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
-
- if (!m_strName.GetLength()) return;
-
- m_strPropNames [m_iPropCount] = m_strName;
- m_strPropValues [m_iPropCount] = m_strValue;
- m_PropTypes [m_iPropCount] = m_iPropType;
-
- m_iPropCount ++;
-
- m_listAll.AddString ((CString)strTypes[m_iPropType]+" "+m_strName+" = "+m_strValue);
-
- GenSrcCode();
- }
-
- void CRegenProps::OnButtonRemove()
- {
- // TODO: Add your control notification handler code here
- if (!m_iPropCount) return;
-
- int iCurSel = m_listAll.GetCurSel();
-
- if (iCurSel != LB_ERR)
- m_listAll.DeleteString(iCurSel);
-
- for (int i = iCurSel; i < --m_iPropCount; i++)
- {
- m_strPropNames [i] = m_strPropNames [i + 1];
- m_strPropValues [i] = m_strPropValues [i + 1];
- m_PropTypes [i] = m_PropTypes [i + 1];
- }
-
- if (iCurSel == m_iPropCount) iCurSel--;
- if (iCurSel >= 0) m_listAll.SetCurSel(iCurSel);
-
- GenSrcCode();
- }
-
- CString AddString(CString strBeg, CString strSuffix, CString strRight)
- {
- CString strResult = "\t\t"+strBeg+strSuffix;
-
- if (strSuffix.GetLength() == 0) strResult += "\t\t\t= ";
- else if (strSuffix.GetLength() <= 4) strResult += "\t\t= ";
- else strResult += "\t= ";
- strResult += strRight+";\n";
-
- return strResult;
- };
-
- void CRegenProps::GenSrcCode()
- {
- // TODO: Add your control notification handler code here
- CString strResult = "";
- CString strStringTableNames = "";
- CString strStringTableValues = "";
- CString strResourceIDS = "";
- CString strIndex, strCount;
- int j = 0;
-
- strCount.Format("%i", m_iPropCount);
-
- for (int i = 0; i < m_iPropCount; i++)
- {
- strIndex.Format("%i", i+1);
-
- strResult += AddString("bstrNames\t[lTmpIndex]", "", (CString)"MakeBSTR(IDS_REGENPROP_" + strIndex + ")");
- strResult += AddString("lTypes\t\t[lTmpIndex]", "", (CString)"VT_" + strVarSizes[m_PropTypes[i]]);
- strResult += AddString("lIDs\t\t[lTmpIndex]", "", "lTmpIndex+1");
- strResult += AddString("varDefaults\t[lTmpIndex]", ".vt", (CString)"VT_" + strVarSizes[m_PropTypes[i]]);
-
- strStringTableNames += "\tIDS_REGENPROP_" + strIndex + "\t\t\"" +
- m_strPropNames[i] + "\"\n";
-
- if (m_PropTypes[i] == 11)
- {
- j++;
- strIndex.Format("%i", j);
-
- strResult += AddString( "varDefaults\t[lTmpIndex]",
- strVarFields[m_PropTypes[i]],
- (CString)"MakeBSTR(IDS_REGENPROP_BSTRVALUE_" + strIndex + ")");
- strStringTableValues += "\tIDS_REGENPROP_BSTRVALUE_" +
- strIndex+"\t\t\"" +
- m_strPropValues[i] + "\"\n";
- }
- else
- strResult += AddString("varDefaults\t[lTmpIndex]", strVarFields[m_PropTypes[i]], m_strPropValues[i]);
-
- strResult += "\t\tlTmpIndex++;\n\n";
- };
-
- if (m_iPropCount)
- strStringTableNames = "STRINGTABLE\tDISCARDABLE\nBEGIN\n" +
- strStringTableNames +
- "END\n";
- if (j)
- strStringTableValues = "STRINGTABLE\tDISCARDABLE\nBEGIN\n" +
- strStringTableValues +
- "END\n";
-
- for (i = 0; i < m_iPropCount; i++)
- {
- strIndex.Format("%i", i + 1);
- strResourceIDS += "#define\tIDS_REGENPROP_" + strIndex + "\t\t\t\t\t";
- strIndex.Format("%i\n", 200+i+1);
- strResourceIDS += strIndex;
- };
-
- for (i = 0; i < j; i++)
- {
- strIndex.Format("%i", i + 1);
- strResourceIDS += "#define\tIDS_REGENPROP_BSTRVALUE_" + strIndex + "\t\t";
- strIndex.Format("%i\n", 200 + m_iPropCount + 1 + i);
- strResourceIDS += strIndex;
- };
-
- m_pclsMain->m_Dictionary [_T("PropertiesCount")] = strCount;
- m_pclsMain->m_Dictionary [_T("RegenPropertiesGenerated")] = strResult;
-
- m_pclsMain->m_Dictionary [_T("RegenPropertiesStringTable")] = strStringTableNames;
- m_pclsMain->m_Dictionary [_T("RegenPropertiesValuesStringTable")] = strStringTableValues;
- m_pclsMain->m_Dictionary [_T("RegenPropertiesIDS")] = strResourceIDS;
- }
-
- void CRegenProps::OnButtonEdit()
- {
- // TODO: Add your control notification handler code here
- if (!m_iPropCount) return;
-
- int iCurSel = m_listAll.GetCurSel();
-
- if (iCurSel == LB_ERR) return;
-
- m_strName = m_strPropNames [iCurSel];
- m_strValue = m_strPropValues [iCurSel];
- m_iPropType = m_PropTypes [iCurSel];
-
- UpdateData(false);
- OnButtonRemove();
- }
-